* Compare estimates to Jones et al. (2022)
* 4/30/2025

clear all
set more off

program main
	check_share_ssi
	regressions_with_more_policies
end

program check_share_ssi // approximate share of Jones et al. (2022) sample on SSI
	// downloaded IPUMS CPS extract 17 on May 31, 2025
	// from https://cps.ipums.org/cps-action/data_requests/download
	use "$raw/cps_00017.dta", clear
	gisid serial pernum year
	replace incssi = . if incssi == 999999 // code for "not in universe"
	su incssi, d
	tab poverty
	
	* impose Jones et al. (2022) sample restrictions
	drop if poverty == 23 // restrict to below 150% of the poverty line (most granular coding)
	drop if inlist(statefip, 2, 6, 15) // remove Alaska, Hawaii, and California
	keep if age >= 60 // elderly subsample is what they use for CAP analysis
	
	* "amplify" their estimates by share on SSI
	qui cou if incssi != 0
	local on_ssi = `r(N)'
	qui cou
	local total_sample = `r(N)'
	local share_ssi = `on_ssi' / `total_sample'
	local amplified_est = 0.013 / `share_ssi'
	di "share on SSI: `share_ssi'"
	di "amplified estimate from Jones et al. (2022): `amplified_est'"
end

program regressions_with_more_policies
	local indiv_controls = "i.sex i.race i.hispan i.edcat age i.diffphys"
	// note for the below definition that Jones et al. exclude has_faceini 
	local state_snap_controls = "i.has_bbce i.has_call i.has_facerec i.has_oapp i.has_no_fp"
	local extra_snap_controls = "i.has_vehexcl i.has_reportsimple certeld0106 i.any_outreach i.has_nonciteld"

	* state-level regression with controls for all SNAP policies included in Jones et al. (2022)
	use "$for_analysis/state_for_regressions_actual_ssi", clear
	drop *startyear has*
	
	merge m:1 statefip year using "$for_analysis/snap_policies_jones_et_al", ///
		assert(2 3) keep(3) nogen
	
	foreach policy in bbce call_any faceini facerec oapp no_fp ///
		vehexcl reportsimple nonciteldfull {
			gen has_`policy' = (year > `policy'_startyear)
	}
	gen any_outreach = (outreach > 0)
	
	reghdfe snap inter `indiv_controls' ///
		state_unemp `state_snap_controls' `extra_snap_controls' ///
		[w = perwt], a(i.statefip i.year) vce(cl statefip)
	est sto state
	
	* singles-couples design
	use "$for_analysis/sc_for_regressions_actual_ssi", clear
	ren inter inter_sc
	drop *startyear has*
	
	merge m:1 statefip year using "$for_analysis/snap_policies_jones_et_al", ///
		assert(2 3) keep(3) nogen
	
	foreach policy in bbce call_any faceini facerec oapp no_fp ///
		vehexcl reportsimple nonciteldfull {
			gen has_`policy' = (year > `policy'_startyear)
	}
	gen any_outreach = (outreach > 0)
	
	reghdfe snap inter_sc `indiv_controls' ///
		state_unemp perc_democrat_2004 hh_income_2003 ///
		`state_snap_controls' `extra_snap_controls' ///
		[w = perwt], a(i.hhtype i.year) vce(cl statefip)
	est sto sc

	* generate table
	esttab state sc ///
		using "$output/jones_et_al_reg", replace ///
		keep(inter inter_sc) order(inter inter_sc) ///
		varlabels(inter "Treated x Post" inter_sc "Single x Post") ///
		se(%5.3f) star(* 0.10 ** 0.05 *** 0.01) stats(N, ///
		labels("N" ) ///
		fmt("%9.0fc" "%9.0fc" "%9.0fc" "%9.0fc" "%9.0fc" "%9.0fc")) scalars() ///
		nomtitles label nonote booktabs
end

* Execute
main
